package org.dragon.controllers;

import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.dragon.commons.Permit;
import org.dragon.models.TestStudent;
import org.dragon.services.RoleService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * Author:     Zhao Yan
 * DateTime:   2023/5/17 10:43
 */
@RestController
@RequestMapping("/test")
@Validated
public class TestController {

    @Resource
    private RoleService roleService;

    @GetMapping("/")
    public Object test(@RequestBody @Valid TestStudent student) {
        return student;
    }

    @GetMapping("/hello")
    public Object hello() {
        return "Hello";
    }

    @GetMapping("/hi")
    public Object hi() {
        return "hi";
    }

    @Permit(roles = "root")
    @GetMapping("/role/{id}")
    public Object testRole(@PathVariable Long id) {
        return roleService.findById(id);
    }
}
